package com.atguigu.gmall.product.service.impl;


import com.atguigu.gmall.model.product.SpuSaleAttr;
import com.atguigu.gmall.product.mapper.SpuSaleAttrMapper;
import com.atguigu.gmall.product.service.SpuSaleAttrService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
* @author Zenglingxiao
* @description 针对表【spu_sale_attr(spu销售属性)】的数据库操作Service实现
* @createDate 2022-03-06 13:03:55
*/
@Service
public class SpuSaleAttrServiceImpl extends ServiceImpl<SpuSaleAttrMapper, SpuSaleAttr>
    implements SpuSaleAttrService {

    @Autowired
    SpuSaleAttrMapper spuSaleAttrMapper;

    @Autowired
    SpuSaleAttrService spuSaleAttrService;

    /**
     * 根据spuId获取销售属性
     * @param spuId
     * @return
     */
    @Override
    public List<SpuSaleAttr> getspuSaleAttrList(Long spuId) {
       return spuSaleAttrMapper.getSpuSaleAttrList(spuId);
    }

    /**
     * 查询skuid对应的spu的所有销售属性名值，并做标记
     * @param spuId
     * @return
     */
    @Override
    public List<SpuSaleAttr> getSpuAndSkuSaleAttrValue(Long skuId, Long spuId) {
        return spuSaleAttrMapper.getSpuAndSkuSaleAttrValue(skuId,spuId);
    }

    /**
     * 查询spu下的所有sku的销售属性值的map组合如：键：1 值：2|3
     * @param spuId
     */
    @Override
    public Map<String, Object> getSpuDeSkuSaleAttrValuesZuhe(Long spuId) {
        Map<String, Object> zuhe = spuSaleAttrMapper.getSpuDeSkuSaleAttrValuesZuhe(spuId);
        HashMap<String , Object> data = new HashMap<>();
        for (Map.Entry<String, Object> entry : zuhe.entrySet()) {
            String key = entry.getKey();
            Map<String,Object> value = (Map<String, Object>) entry.getValue();
            Object skuId = value.get("sku_id");
            data.put(key,skuId);
        }
        return data;
    }

}




